home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / DMTDEMOS / GETBOOT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-02  |  4KB  |  131 lines

  1. program GetBootSample;
  2.  
  3. (*
  4.  
  5.  Every DOS disk has a special sector called the boot sector responsible for
  6.  loading DOS or displaying the "Non-System disk" error message. In addition,
  7.  the boot sector contains information about the disk, such as the number of
  8.  sectors, tracks, FATs, and so on. This program reads the boot sector for the
  9.  drive specified.
  10.  
  11. *)
  12.  
  13.  uses crt, DMT;
  14.  
  15.  var
  16.    BootSectBuffer : BootSectStruct;  { The BootSectStruct data type is defined in the DMT unit }
  17.  
  18.    LogDrvs        : ListOfDrvs;      { The ListOfDrvs data type is defined in the DMT unit }
  19.  
  20.    BPBbuffer      : DevParamsStruct; { The DevParamsStruct data type is defined in the DMT unit }
  21.  
  22.    BootSectors,
  23.    StartbootSect,
  24.    Head,
  25.    Track,
  26.    Sect           : word;
  27.  
  28.    HugeSectors    : longint;
  29.  
  30.    DrvsCount,
  31.    Index          : byte;
  32.  
  33.    DrvLetter      : char;
  34.  
  35. begin
  36.   Color( 7, 0 );
  37.   clrscr;
  38.  
  39.   GetDrvs( LogDrvs, DrvsCount );   { Call GetDrvs procedure }
  40.  
  41.   write( #13#10, 'Select Drive ( ');
  42.  
  43.   for Index := 1 to DrvsCount do
  44.     write( LogDrvs[ Index ], ': ' );
  45.  
  46.   write( ') [ :]' );
  47.  
  48.   gotoxy( wherex - 3, wherey );
  49.   DrvLetter := upcase( readkey );
  50.   writeln( DrvLetter );
  51.  
  52.   GetBPB( DrvLetter, BPBbuffer );  { Call GetBPB procedure }
  53.  
  54.   if ( ErrFlag ) then
  55.     begin
  56.       writeln( #7 );
  57.       writeln( ShowError( GetErrCode ) );
  58.     end
  59.   else
  60.     begin
  61.       with BPBbuffer do
  62.         begin
  63.  
  64.           (* Determines the number of boot sectors to read *)
  65.  
  66.           BootSectors := BootSects;
  67.  
  68.           (* Determines the start of the first boot sector *)
  69.  
  70.           StartbootSect := HiddenSects;
  71.  
  72.           (*
  73.             Translates the logical boot sector number into a physical sector
  74.             consisting of head, track, and sector numbers.
  75.           *)
  76.  
  77.           Head  := ( StartbootSect div SectsPerTrack ) mod NumOfHeads;
  78.           Track := StartbootSect div ( SectsPerTrack * NumOfHeads );
  79.           Sect  := StartbootSect mod SectsPerTrack;
  80.         end;
  81.  
  82.       (* Reads the boot sector from disk and place it into a buffer *)
  83.  
  84.       ReadSect( DrvLetter, Head, Track, Sect, BootSectors, addr( BootSectBuffer ) );
  85.  
  86.       with BootSectBuffer do
  87.         begin
  88.  
  89.           if ( NumOfSects = 0 ) then
  90.             HugeSectors := BigSects
  91.           else
  92.             HugeSectors := NumOfSects;
  93.  
  94.           clrscr;
  95.           writeln('             BOOT SECTOR          ' );
  96.           writeln;
  97.           writeln(' Drive specified                : ', DrvLetter );
  98.           writeln(' Disk was formatted with        : ', OemName );
  99.           writeln(' Media descriptor code          : ', WrdToHex( MediaCode ),'h' ) ;
  100.           writeln(' Bytes per sector               : ', BytesPerSect );
  101.           writeln(' Sectors per cluster            : ', SectsPerClust );
  102.           writeln(' Sectors per track              : ', SectsPerTrack );
  103.           writeln(' Number of sectors on disk      : ', InsComma( HugeSectors ) );
  104.           writeln(' Number of heads (sides)        : ', NumOfHeads );
  105.           writeln(' Number of hidden sectors       : ', HiddenSects );
  106.           writeln(' Number of boot sectors         : ', BootSects );
  107.           writeln(' Number of FAT copies           : ', NumOfFATs );
  108.           writeln(' Sectors used by each FAT       : ', SectsPerFAT );
  109.           writeln(' Maximum root-directory entries : ', RootDirEntries );
  110.           write  (' First hard disk?               : ' );
  111.  
  112.           if ( DrvNumber = $80 ) then
  113.             writeln( 'YES' )
  114.           else
  115.             writeln( 'NO' );
  116.  
  117.           if ( ExtBootSign = $29 ) then
  118.             begin
  119.               writeln(' Disk serial number             : ', WrdToHex( DskSerialNum2 ), '-', WrdToHex( DskSerialNum1 ) );
  120.               writeln(' Disk volume name               : ', VolLabel );
  121.               writeln(' File System Type               : ', FATtype );
  122.             end;
  123.  
  124.         end;
  125.     end;
  126.   GetEnter;
  127. end.
  128.  
  129.  
  130.  
  131.